package mongoDB;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.GroupOperation;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring-mongodb.xml" })
public class TestMongoSpiring {
	@Autowired
	private UserModelRepository ur;
	@Autowired
	private MongoTemplate mt;

	@Test
	public void test1() {
//		Aggregation aggregation= new Aggregation(group("userid")
//			       .sum(1).as("count")); 
		
//		mt.aggregate(aggregation, collectionName, outputType)
		final String COL_NAME = "tuser1";

		// add
		UserModel um = new UserModel();
		um.setAge(12222);
		um.setName("nee1222");
		um.setUserId("u211");
		mt.insert(um, COL_NAME);

	}

	@Test
	public void test2() {
		UserModel um = new UserModel();
		um.setAge(1222233);
		um.setName("nwwww1");
		um.setUserId("wwwwwwwww1");
		ur.save(um);

		System.out.println(ur.findOne("wwwwwwwww1"));
	}

}
